package com.greedy.tank;

import java.awt.*;

/**
 * @Author: Yanxy
 * @Date: Created in:2023-07-05
 * Description: 子弹
 */
public class Bullet {

    /**
     * 子弹速度
     */
    private static final int SPEED = 10;

    private static final int WIDTH = 30, HEIGHT = 30;

    /**
     * 子弹坐标
     */
    private int x, y;

    /**
     * 子弹方向
     */
    private Dir dir;

    /**
     * 构造器
     *
     * @param x   x
     * @param y   y
     * @param dir 方向
     */
    public Bullet(int x, int y, Dir dir) {
        this.x = x;
        this.y = y;
        this.dir = dir;
    }

    /**
     * getter
     *
     * @param g 画笔
     */
    public void paint(Graphics g) {
        // 画一个圆
        Color color = g.getColor();
        g.setColor(Color.RED);
        g.fillOval(x, y, WIDTH, HEIGHT);
        g.setColor(color);
        this.move();
    }

    /**
     * 移动
     */
    private void move() {
        switch (dir) {
            case LEFT:
                x -= SPEED;
                break;
            case UP:
                y -= SPEED;
                break;
            case RIGHT:
                x += SPEED;
                break;
            case DOWN:
                y += SPEED;
            default:
                break;
        }
    }

}
